<?php
/**
 * Created by PhpStorm.
 * User: waw
 * Date: 2019/6/21
 * Time: 10:58
 */
if($_SERVER["REQUEST_METHOD"]=="GET"){
    return;
}
$uid=$_REQUEST["uid"];
$imgUrl=$_REQUEST["imgUrl"];
$good_id=$_REQUEST["good_id"];
$good_name=$_REQUEST["good_name"];
$good_city=$_REQUEST["good_city"];
$good_num=$_REQUEST["good_num"];
$good_geld=$_REQUEST["good_geld"];
$total=$good_num*$good_geld;

include "./DBhelper.php";

$query="SELECT * from  `cartlists` WHERE g_name='".$good_name."'AND`uid`='".$uid."'";
//print_r($query);
$result = sqlQuery($query);
if ($result->num_rows>=1){
    $update="UPDATE `cartlists` SET `g_num`=g_num+'".$good_num."',`g_total`=`g_preis`*`g_num` WHERE g_name='".$good_name."'AND`uid`='".$uid."'";
    $updateRes=sqlQuery($update);
    if ($updateRes==1){
        print_r(json_encode(array('msg'=>"修改成功","status"=>1)));
    }else{
        print_r(json_encode(array("msg"=>"修改cg","status"=>2)));
    }
}else{
    $insert="INSERT INTO `cartlists`(`g_id`,`g_name`,`g_preis`,`g_total`,`g_city`,`g_num`,`uid`,`g_url`)";
    $insert .="VALUES('".$good_id."','".$good_name."','".$good_geld."','".$good_num*$good_geld."','".$good_city."','".$good_num."','".$uid."','".$imgUrl."')";
   print_r($insert);
    $updateRes=sqlQuery($insert);
    if ($updateRes==1){
        print_r(json_encode(array('msg'=>"插入成功","status"=>3)));
    }else{
        print_r(json_encode(array('msg'=>"插入失败","status"=>4)));
    }
}